import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';

import { HttpServer } from '@core/net/http-server';
import { PageInfo } from '@core/model/pageInfo';
import { UrlManager } from '@shared/url/url.manager';

import { Role } from '../model/role';

@Injectable()
export class RoleService {

  constructor(
    private httpServer: HttpServer
  ) { }

  getAllRoles(pageNo: number, pageSize: number): Observable<PageInfo<Role>> {
    return this.httpServer.get(UrlManager.role.getAllRolesByPageUrl, {
      pageNo: pageNo,
      pageSize: pageSize
    });
  }
  getAllStoreRoles(pageNo: number, pageSize: number): Observable<PageInfo<Role>> {
    return this.httpServer.get(UrlManager.role.getStoreRoleByPageUrl, {
      pageNo: pageNo,
      pageSize: pageSize
    });
  }

  getRoleById(roleId: string): Observable<Role> {
    return this.httpServer.get(UrlManager.role.getRoleByIdUrl, {id: roleId});
  }

  addRole(role: Role): Observable<boolean> {
    return this.httpServer.post(UrlManager.role.addRoleUrl, role);
  }

  updateRole(role: Role): Observable<boolean> {
    return this.httpServer.post(UrlManager.role.uppdateRoleUrl, role);
  }

  deltetRole(id: string): Observable<boolean> {
    return this.httpServer.get(UrlManager.role.deleteRoleUrl, {
      id: id
    });
  }

  saveRoleMenuFunction(roleId: number, mId: number[]): Observable<boolean> {
    return this.httpServer.post(UrlManager.role.saveRoleMenuFunction, {
      roleId: roleId,
      mId: mId
    });
  }
}
